home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / blob / blob_tes.frm next >
Text File  |  1995-09-06  |  8KB  |  279 lines

  1. VERSION 2.00
  2. Begin Form BLOB_Test 
  3.    BackColor       =   &H8000000F&
  4.    Caption         =   "BLOB Test Form"
  5.    ClientHeight    =   4290
  6.    ClientLeft      =   810
  7.    ClientTop       =   1470
  8.    ClientWidth     =   6375
  9.    Height          =   4695
  10.    Left            =   750
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4290
  13.    ScaleWidth      =   6375
  14.    Top             =   1125
  15.    Width           =   6495
  16.    Begin CommandButton Command4 
  17.       Caption         =   "Add New Record"
  18.       Height          =   372
  19.       Left            =   2160
  20.       TabIndex        =   10
  21.       Top             =   3360
  22.       Width           =   1692
  23.    End
  24.    Begin TextBox Text2 
  25.       DataField       =   "Input_Size"
  26.       DataSource      =   "Data1"
  27.       Enabled         =   0   'False
  28.       Height          =   288
  29.       Index           =   2
  30.       Left            =   120
  31.       TabIndex        =   9
  32.       Top             =   3120
  33.       Width           =   972
  34.    End
  35.    Begin TextBox Text2 
  36.       DataField       =   "File_Name"
  37.       DataSource      =   "Data1"
  38.       Enabled         =   0   'False
  39.       Height          =   288
  40.       Index           =   1
  41.       Left            =   120
  42.       TabIndex        =   8
  43.       Top             =   2760
  44.       Width           =   6012
  45.    End
  46.    Begin TextBox Text2 
  47.       DataField       =   "CNT"
  48.       DataSource      =   "Data1"
  49.       Enabled         =   0   'False
  50.       Height          =   288
  51.       Index           =   0
  52.       Left            =   120
  53.       TabIndex        =   7
  54.       Top             =   2400
  55.       Width           =   972
  56.    End
  57.    Begin CommandButton Command3 
  58.       Caption         =   "Write File"
  59.       Height          =   372
  60.       Left            =   4440
  61.       TabIndex        =   4
  62.       Top             =   1800
  63.       Width           =   1812
  64.    End
  65.    Begin CommandButton Command2 
  66.       Caption         =   "Read File"
  67.       Height          =   372
  68.       Left            =   2400
  69.       TabIndex        =   3
  70.       Top             =   1800
  71.       Width           =   1812
  72.    End
  73.    Begin TextBox Text1 
  74.       Height          =   288
  75.       Index           =   1
  76.       Left            =   120
  77.       TabIndex        =   2
  78.       Top             =   1320
  79.       Width           =   6132
  80.    End
  81.    Begin PictureBox CMDialog1 
  82.       Height          =   480
  83.       Left            =   5880
  84.       ScaleHeight     =   450
  85.       ScaleWidth      =   1170
  86.       TabIndex        =   11
  87.       Top             =   0
  88.       Width           =   1200
  89.    End
  90.    Begin CommandButton Command1 
  91.       Caption         =   "Get File Name"
  92.       Height          =   372
  93.       Left            =   120
  94.       TabIndex        =   1
  95.       Top             =   1800
  96.       Width           =   2052
  97.    End
  98.    Begin Data Data1 
  99.       Caption         =   "Data1"
  100.       Connect         =   ""
  101.       DatabaseName    =   "BLOBTEST.MDB"
  102.       Exclusive       =   0   'False
  103.       Height          =   270
  104.       Left            =   2040
  105.       Options         =   0
  106.       ReadOnly        =   0   'False
  107.       RecordSource    =   "Blob_Test_Table"
  108.       Top             =   3840
  109.       Width           =   1872
  110.    End
  111.    Begin TextBox Text1 
  112.       Height          =   288
  113.       Index           =   0
  114.       Left            =   120
  115.       TabIndex        =   0
  116.       Top             =   480
  117.       Width           =   6132
  118.    End
  119.    Begin Label Label1 
  120.       BackColor       =   &H8000000F&
  121.       Caption         =   "Output File && Path Name"
  122.       FontBold        =   -1  'True
  123.       FontItalic      =   0   'False
  124.       FontName        =   "Arial"
  125.       FontSize        =   9
  126.       FontStrikethru  =   0   'False
  127.       FontUnderline   =   0   'False
  128.       Height          =   228
  129.       Index           =   1
  130.       Left            =   120
  131.       TabIndex        =   6
  132.       Top             =   1080
  133.       Width           =   3132
  134.    End
  135.    Begin Label Label1 
  136.       BackColor       =   &H8000000F&
  137.       Caption         =   "Input File && Path Name"
  138.       FontBold        =   -1  'True
  139.       FontItalic      =   0   'False
  140.       FontName        =   "Arial"
  141.       FontSize        =   9
  142.       FontStrikethru  =   0   'False
  143.       FontUnderline   =   0   'False
  144.       Height          =   228
  145.       Index           =   0
  146.       Left            =   120
  147.       TabIndex        =   5
  148.       Top             =   240
  149.       Width           =   3132
  150.    End
  151. End
  152.  
  153. Option Explicit
  154.  
  155.  
  156. Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFilename As String, ByVal nSize As Integer) As Integer
  157.  
  158. Sub Command1_Click ()
  159.     CMDialog1.Action = 1
  160.  
  161.     Text1(0) = CMDialog1.Filename
  162.     Text1(1) = "C:\TEMP\" & CMDialog1.Filetitle
  163.  
  164. End Sub
  165.  
  166. Sub Command2_Click ()
  167.  
  168.     If Data1.Recordset.RecordCount = 0 Then
  169.     Data1.Recordset.AddNew
  170.     Data1.Recordset.Update
  171.     End If
  172.     
  173.     If (Len(Text1(0)) = 0) Then
  174.     MsgBox "Require File Name To Read." & Chr(10) & "Select 'Get File Name' first."
  175.     Exit Sub
  176.     End If
  177.  
  178.     ReadBigFile (Text1(0))
  179. End Sub
  180.  
  181. Sub Command3_Click ()
  182.  
  183.     If (Len(Text1(1)) = 0) Then
  184.     MsgBox "Require File Name To Read." & Chr(10) & "Select 'Get File Name' first or edit 'Output File Name'."
  185.     Exit Sub
  186.     End If
  187.  
  188.     WriteBigFile (Text1(1))
  189. End Sub
  190.  
  191. Sub Command4_Click ()
  192.     Data1.Recordset.AddNew
  193.     Data1.Recordset.Update
  194. End Sub
  195.  
  196. Sub Form_Load ()
  197.     Dim temp As String
  198.  
  199.     temp = Left$(App.Path, 1)
  200.     ChDrive temp
  201.     ChDir App.Path
  202.  
  203. End Sub
  204.  
  205. Sub ReadBigFile (FName As String)
  206. 'AppendChunk Method Example
  207. 'This example uses AppendChunk with a data control to save the contents of a separate file into a field.  You would call this
  208. 'procedure with the path and name of the file you want to put into your database.  This procedure works for either Memo or Long
  209. 'Binary fields.
  210.  
  211.     Dim TotalSize As Long, CurChunk As String
  212.     Dim I As Integer, FNum As Integer, ChunkSize As Integer
  213.  
  214.     Screen.MousePointer = 11
  215.  
  216.     ChunkSize = 12000       ' Set size of chunk.
  217.     Data1.Recordset.Edit    ' Enter Edit mode.
  218.     Data1.Recordset.Fields(Field_Name) = "" ' Clear Comments field.
  219.     FNum = FreeFile ' Get free file number.
  220.     Open FName For Binary As #FNum  ' Open the file.
  221.     TotalSize = LOF(FNum)
  222.  
  223.     Text2(1) = FName
  224.     Text2(2) = TotalSize
  225.  
  226.     Do While Not EOF(FNum)
  227.         If TotalSize - Seek(FNum) < ChunkSize Then
  228.             ChunkSize = TotalSize - Seek(FNum)
  229.             If ChunkSize <= 0 Then Exit Do
  230.         End If
  231.         CurChunk = String$(ChunkSize + 1, 32)
  232.         Get #FNum, , CurChunk   ' Read chunk from file.
  233.  
  234.     ' Append chunk to Comments field.
  235.         Data1.Recordset.Fields(Field_Name).AppendChunk (CurChunk)
  236.     Loop
  237.     Data1.Recordset.Update  ' Save the record.
  238.     Close FNum      ' Close the file.
  239.  
  240.     Screen.MousePointer = 0
  241.     MsgBox "Stored file " & FName & Chr(10) & "Input file size = " & TotalSize & Chr(10) & "Into '" & Field_Name & "'."
  242. End Sub
  243.  
  244. Sub WriteBigFile (FName As String)
  245. 'GetChunk and FieldSize Methods Example
  246. 'This example uses GetChunk with a data control to save the contents of a field to a separate file.  You would call this procedure
  247. 'with the path and name of the file where you want to save the contents of the field.  This procedure works for either text or binary
  248. 'fields.
  249.  
  250.  
  251.     Dim NumChunks As Long, TotalSize As Long
  252.     Dim RemChunk As Integer, CurSize As Integer
  253.     Dim I As Integer, FNum As Integer, CurChunk As String
  254.  
  255.     Screen.MousePointer = 11
  256.  
  257.     ChunkSize = 2000        ' Set size of chunk.
  258.     ' Get field size.
  259.     TotalSize = Data1.Recordset.Fields(Field_Name).FieldSize()
  260.     NumChunks = TotalSize \ ChunkSize       ' Set number of chunks.
  261.     ' Set number of remaining bytes.
  262.     RemChunk = TotalSize Mod ChunkSize
  263.     ' Set starting size of chunk.
  264.     CurSize = ChunkSize
  265.     FNum = FreeFile ' Get free file number.
  266.     Open FName For Binary As #FNum  ' Open the file.
  267.     For I = 0 To NumChunks
  268.         If I = NumChunks Then CurSize = RemChunk
  269.         CurChunk = Data1.Recordset.Fields(Field_Name).GetChunk(I * ChunkSize, CurSize)
  270.         Put #FNum, , CurChunk   ' Write chunk to file.
  271.     Next I
  272.     TotalSize = LOF(FNum)
  273.     Close FNum
  274.  
  275.     Screen.